const express=require('express');
const path=require('path');
const cors=require('cors');
const jwt=require('express-jwt');
const app=express();
app.listen(3007,()=>{console.log('大事件接口启动')});
//--------配置应用级别中间件--------------------
app.use(cors());
app.use(express.urlencoded({extended:false}));

//-------------- 解析token字符串--------------
app.use(jwt({secret:'bigevent'}).unless({path:/^\/api/}));
//---------------加载路由模块---------------------
app.use('/api',require(path.join(__dirname,'routers','login')));
app.use('/my/article',require(path.join(__dirname,'routers','category')));
app.use('/my/article',require(path.join(__dirname,'routers','article')));
app.use('/my',require(path.join(__dirname,'routers','user')));

//处理错误中间件
app.use(function(err,req,res,next){
	if(err.name==='UnauthorizedError'){
		console.log(err.message);
		res.status(401).send({status:1,message:'身份认证失败'});
	}
})